SET NOCOUNT ON
GO

IF OBJECT_ID('Test_') IS NOT NULL DROP PROCEDURE Test_
IF OBJECT_ID('Test_DEFAULT') IS NOT NULL DROP PROCEDURE Test_DEFAULT
IF OBJECT_ID('Debug_') IS NOT NULL DROP PROCEDURE Debug_
IF OBJECT_ID('Debug_DEFAULT') IS NOT NULL DROP PROCEDURE Debug_DEFAULT
IF OBJECT_ID('SayHallo_') IS NOT NULL DROP FUNCTION SayHallo_
IF OBJECT_ID('SayHallo_DEFAULT') IS NOT NULL DROP FUNCTION SayHallo_DEFAULT
DELETE qic.AspectConfig where WhenInterfaceName = 'Test_'
GO

CREATE PROCEDURE Test_ @Name varchar(50)
AS
BEGIN
	RETURN NULL
END
GO

CREATE PROCEDURE Test_DEFAULT @Name varchar(50), @InterfaceName varchar(50)
AS
BEGIN
	PRINT 'this is test_ called by ' + @InterfaceName + ' and @Name = ' + @Name
END
GO

CREATE PROCEDURE Debug_ @SaySomething varchar(50),  @Name varchar(50), @InterfaceContext XML
AS
BEGIN
	RETURN NULL
END
GO

CREATE PROCEDURE Debug_DEFAULT @SaySomething varchar(50),  @Name varchar(50), @InterfaceContext XML
AS
BEGIN
	PRINT 'this is Debug_ saying ' + @SaySomething + ' and @Name = ' + @Name
	PRINT 'this is the interfacecontext: ' + cast(@InterfaceContext as varchar(max))
END
GO

CREATE FUNCTION dbo.SayHallo_(@Name varchar(50))
RETURNS VARCHAR(50)
AS
BEGIN
	RETURN NULL
END
GO

CREATE FUNCTION dbo.SayHallo_DEFAULT(@Name varchar(50))
RETURNS VARCHAR(50)
AS
BEGIN
	RETURN 'HELLO ' + @Name + '!'
END
GO

INSERT INTO qic.AspectConfig (WhenInterfaceName, WhenActionName, ThenInterfaceName, ThenReturnToken) 
VALUES ('Test_','BEFORE','SayHallo_','@SaySomething')
INSERT INTO qic.AspectConfig (WhenInterfaceName, WhenActionName, ThenInterfaceName,ThenReturnToken) 
VALUES ('Test_','AFTER','DEBUG_','@DebugReturn')

GO

exec qic.Compile
exec Test_'Modermodemet'

PRINT '--'
PRINT 'The generated interfaces'
PRINT '--'
exec qic.ScriptInterface 'SayHallo_'
exec qic.ScriptInterface 'Debug_'
exec qic.ScriptInterface 'Test_'
PRINT '--'
GO

IF OBJECT_ID('Test_') IS NOT NULL DROP PROCEDURE Test_
IF OBJECT_ID('Test_DEFAULT') IS NOT NULL DROP PROCEDURE Test_DEFAULT
IF OBJECT_ID('Debug_') IS NOT NULL DROP PROCEDURE Debug_
IF OBJECT_ID('Debug_DEFAULT') IS NOT NULL DROP PROCEDURE Debug_DEFAULT
IF OBJECT_ID('SayHallo_') IS NOT NULL DROP FUNCTION SayHallo_
IF OBJECT_ID('SayHallo_DEFAULT') IS NOT NULL DROP FUNCTION SayHallo_DEFAULT
DELETE qic.AspectConfig where WhenInterfaceName = 'Test_'
GO